<template>
  <div class="home-box" ref="homeBox">
    <div class="topBar">
      <div class="seachBox">
        <a class="logoText"> </a>
        <van-search
          v-model="SearchValue"
          placeholder="搜索商品,共98300款好物"
        />
      </div>
      <div class="tabBox">
        <van-tabs>
          <van-tab
            v-for="(item, index) in categoryList"
            :title="item"
            :key="index"
          >
          </van-tab>
        </van-tabs>
        <!-- 展开标签 -->
        <van-icon name="arrow-down"></van-icon>
      </div>
    </div>
    <div class="content" v-if="!skeleton">
      <!-- 轮播图 -->
      <van-swipe :autoplay="3000">
        <van-swipe-item v-for="(image, index) in focusList" :key="index">
          <img v-lazy="image" />
        </van-swipe-item>
      </van-swipe>
      <!-- 政策选项 -->
      <div class="policyDesBox">
        <div
          class="policeDes"
          v-for="(item, index) in policyDescList"
          :key="index"
        >
          <img class="icon" :src="item.icon" />
          {{ item.desc }}
        </div>
      </div>
      <!-- kingKongModule -->
      <div class="kingKongBox">
        <a
          class="kingKongItem"
          v-for="(item, index) in kingKongList"
          :key="index"
          :href="item.schemeUrl"
        >
          <img :src="item.picUrl" alt="" />
          <span class="text">{{ item.text }}</span>
        </a>
      </div>
      <!-- 广告推广页面 -->
      <div class="bigPromotionBox">
        <a :href="bigPromotion.schemeUrl">
          <img :src="bigPromotion.picUrl" />
        </a>
      </div>
      <!-- indexActivityModule -->
      <div class="indexActivityBox">
        <div class="bigTitle">新人专享礼</div>
        <div class="content">
          <div class="leftBox">
            <div class="leftTitle">新人专享礼包</div>
            <div class="imgBox">
              <a href="https://act.you.163.com/act/pub/qAU4P437asfF.html">
                <img
                  src="//yanxuan.nosdn.127.net/352b0ea9b2d058094956efde167ef852.png"
                  alt=""
                />
              </a>
            </div>
          </div>
          <div class="rightBox">
            <a
              :href="item.targetUrl"
              class="indexActivityItem"
              v-for="(item, index) in indexActivityList"
              :key="index"
            >
              <div class="desc">
                <span class="title">{{ item.title }}</span>
                <span class="subTitle">{{ item.subTitle }}</span>
                <span class="tag">{{ item.tag }}</span>
              </div>
              <div class="imgBox">
                <img v-lazy="item.showPicUrl" class="theImg" />
              </div>
              <div class="priceBox">
                <span class="originPrice">{{ item.originPrice }}</span>
                <span class="activityPrice">{{ item.activityPrice }}</span>
              </div>
            </a>
          </div>
        </div>
      </div>
      <!-- 类目热销榜 -->
      <div class="categoryHotSellModule">
        <div class="hotSellTitle">{{ categoryHotSellModule.title }}</div>
        <div class="content">
          <div
            class="hotSellBox"
            v-for="(item, index) in categoryHotSellModule.categoryList"
            :key="index"
            :class="index < 2 ? 'bigModule' : ''"
          >
            <div class="subTitle">{{ item.categoryName }}</div>
            <a :href="item.targetUrl" class="imgBox">
              <img v-lazy="item.showPicUrl" />
            </a>
          </div>
          <div class="hotSellBox empty"></div>
          <div class="hotSellBox empty"></div>
        </div>
      </div>
      <!-- sceneLightShoppingGuideModule -->
      <div class="shoppingGuideModule">
        <div
          class="shoppingGuideBox"
          v-for="(item, index) in sceneLightShoppingGuideModule"
          :key="index"
        >
          <div
            class="title"
            :style="{ color: '#' + item.styleItem.titleColor }"
          >
            {{ item.styleItem.title }}
          </div>
          <div class="desc" :style="{ color: '#' + item.styleItem.descColor }">
            {{ item.styleItem.desc }}
          </div>
          <a :href="item.styleItem.targetUrl">
            <span
              class="imgBox"
              v-for="(pic, i) in item.styleItem.picUrlList"
              :key="i"
            >
              <img v-lazy="pic" />
            </span>
          </a>
        </div>
      </div>
    </div>
    <!-- 骨架屏 -->
    <div class="skeleton-box" v-show="skeleton">
      <!-- <van-skeleton title :row="5"></van-skeleton> -->
      <img
        src="//yanxuan-static.nosdn.127.net/hxm/yanxuan-node-wap/style/img/skeleton/index-788de73f547e393e8b8b.png"
        class="skeleton-image"
      />
      <!--  href="//yanxuan-static.nosdn.127.net/hxm/yanxuan-node-wap/style/img/skeleton/index-788de73f547e393e8b8b.png"-->
    </div>
  </div>
</template>

<script>
import { mapStates, mapActions, mapMutations, mapGetters } from "@/store";
export default {
  name: "Home",
  data() {
    return {
      allData: null,
      skeleton: true,
      SearchValue: "",
      active: "0",
      categoryList: [
        "推荐",
        "居家生活",
        "服饰鞋包",
        "美食酒水",
        "个护清洁",
        "母婴亲子",
        "运动履行",
        "数码家电",
        "严选全球",
      ],
    };
  },
  computed: {
    focusList() {
      return this.allData.focusList.map((item) => item.picUrl);
    },
    policyDescList() {
      return this.allData.policyDescList;
    },
    kingKongList() {
      return this.allData.kingKongModule.kingKongList;
    },
    bigPromotion() {
      return this.allData.bigPromotionModule.floorList[0].cells[0];
    },
    indexActivityList() {
      return this.allData.indexActivityModule;
    },
    categoryHotSellModule() {
      return this.allData.categoryHotSellModule;
    },
    sceneLightShoppingGuideModule() {
      return this.allData.sceneLightShoppingGuideModule;
    },
  },
  methods: {
    async queryData() {
      let { data } = await this.$api.homeData();
      this.allData = data.data;
      this.skeleton = !this.allData ? true : false;
      console.log(this.allData);
    },
  },
  created() {
    this.queryData();
  },

  watch: {},
};
</script>

<style lang="less">
.home-box {
  position: relative;
  .topBar {
    background: #fff;
    z-index: 99;
    position: fixed;
    top: 0;
    left: 0;
    .seachBox {
      display: flex;
      align-items: center;
      padding: 0px 20px;
      .logoText {
        background-image: url(//yanxuan-static.nosdn.127.net/hxm/yanxuan-node-wap/style/img/index-20a8c6c35d0ec7b54782d2098282371f.png);
        width: 92px;
        height: 26.67px;
        background-size: 250.67px 250.67px;
        background-position: -84px -168px;
        display: block;
        margin-right: 13.33px;
      }
      .van-search {
        padding: 10px 0px;
        .van-search__content {
          border-radius: 5px;
          background: #ededed;
          width: 340px;
          height: 40px;
        }
      }
    }
    .tabBox {
      vertical-align: middle;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 20px;
      .van-tabs--line.van-tabs {
        width: 8.4rem;
        display: inline-block;
        .van-tabs__wrap {
          height: 0.8rem;
          .van-tabs__nav {
            padding: 0;
            .van-tab {
              padding: 0 0.4rem;
            }
            .van-tabs__line {
              bottom: 0.01rem;
              left: -0.04rem;
              height: 0.05rem;
              width: 1.2rem;
            }
          }
        }
      }
      .van-icon {
        font-size: 0.5rem;
        color: #aaa;
        text-align: right;
      }
    }
  }
  .content {
    background: #eeeeee;
    .van-swipe {
      background: #fff;
      padding-top: 2rem;
      height: 4rem;
      .van-swipe__track {
        .van-swipe-item {
          position: relative;
          img {
            position: absolute;
            width: 100%;
            top: -50%;
            transform: translateY(30%);
          }
        }
      }
      .van-swipe__indicators {
        bottom: 0.4rem;
        .van-swipe__indicator {
          width: 0.6rem;
          height: 0.06rem;
          border-radius: 0;
          &.van-swipe__indicator--active {
            background: #fff;
          }
        }
      }
    }
    .policyDesBox {
      display: flex;
      justify-content: space-around;
      padding: 0 0.1rem;
      background: #fff;
      .policeDes {
        height: 1rem;
        line-height: 1rem;
        .icon {
          vertical-align: middle;
          width: 0.4rem;
          margin-right: 0.01rem;
        }
      }
    }
    .kingKongBox {
      padding: 0 0.1rem;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      background: #fff;
      .kingKongItem {
        padding: 0 0.15rem;
        padding-bottom: 0.3rem;
        color: #333;
        text-align: center;
        img {
          width: 1.5rem;
        }
        .text {
          display: block;
        }
      }
    }
    .bigPromotionBox {
      background: #fff;
      margin-bottom: 0.3rem;
      img {
        width: 100%;
      }
    }
    .indexActivityBox {
      background: #fff;
      margin-bottom: 0.3rem;
      .bigTitle {
        width: 3.2rem;
        margin: auto;
        text-align: center;
        height: 1rem;
        line-height: 1rem;
        font-size: 0.43rem;
        position: relative;
        &::before {
          content: "";
          width: 0.3rem;
          height: 0.04rem;
          background: #000;
          position: absolute;
          top: 50%;
          left: 0;
        }
        &::after {
          content: "";
          width: 0.3rem;
          height: 0.04rem;
          background: #000;
          position: absolute;
          top: 50%;
          right: 0;
        }
      }
      .content {
        background: #fff;
        display: flex;
        padding: 0.4rem;
        padding-top: 0;
        .leftBox {
          width: 4.8rem;
          background: #f9e9cf;
          border-radius: 0.1rem;
          margin-right: 0.05rem;
          .imgBox {
            width: 3.6rem;
            margin: 0 auto;
            padding-top: 0.25rem;
            img {
              width: 100%;
            }
          }
          .leftTitle {
            font-size: 0.4rem;
            height: 1.2rem;
            line-height: 1.2rem;
            text-align: center;
          }
        }
        .rightBox {
          .indexActivityItem {
            position: relative;
            box-sizing: border-box;
            display: block;
            width: 4.6rem;
            height: 2.8rem;
            background: #fbe2d3;
            color: #333;
            border-radius: 0.1rem;
            &:last-child {
              background: #ffecc2;
              margin-top: 0.05rem;
            }
            .desc {
              position: absolute;
              top: 10%;
              left: 10%;
              z-index: 2;
              span {
                display: block;
              }
              .title {
                font-size: 0.45rem;
                padding-bottom: 0.1rem;
              }
              .subTitle {
                color: #7f7f7f;
              }
              .tag {
                background: #cbb693;
                border-radius: 0.04rem;
                color: #fff;
                font-size: 0.3rem;
                line-height: 0.4rem;
                padding: 0 0.1rem;
                text-align: center;
              }
            }
            .imgBox {
              position: absolute;
              right: 0;
              bottom: 0;
              .theImg {
                display: block;
                right: 0;
                width: 2.5rem;
              }
            }
            .priceBox {
              position: absolute;
              top: 0.15rem;
              right: 0.3rem;
              box-sizing: border-box;
              width: 1.1rem;
              height: 1.1rem;
              background: #f59524;
              color: #fff;
              padding-top: 0.1rem;
              text-align: center;
              border-radius: 0.55rem;
              span {
                display: block;
              }
              .activityPrice {
                text-decoration: line-through;
              }
            }
          }
        }
      }
    }
    .categoryHotSellModule {
      background: #fff;
      margin-bottom: 0.3rem;
      padding-top: 0.1rem;
      padding-bottom: 0.2rem;
      width: 100%;
      .hotSellTitle {
        width: 3.2rem;
        margin: auto;
        text-align: center;
        height: 1rem;
        line-height: 1rem;
        font-size: 0.43rem;
      }
      .content {
        background: #fff;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
        padding: 0 0.4rem;
        .hotSellBox {
          width: 2.2rem;
          height: 2.4rem;
          background: #f5f5f5;
          border-radius: 0.08rem;
          margin-bottom: 0.08rem;
          margin-right: 0.08rem;
          &.empty {
            background: #fff;
          }
          .subTitle {
            margin-top: 0.2rem;
            font-size: 0.22rem;
            text-align: center;
          }
          .imgBox {
            display: block;
            margin: auto;
            width: 1.5rem;
            height: 1.5rem;
            img {
              width: 100%;
            }
          }
        }
        .hotSellBox.bigModule {
          width: 4.52rem;
          background: #ebeff6;
          position: relative;
          .subTitle {
            position: absolute;
            top: 40%;
            left: 10%;
            transform: translateY(-50%);
            margin-top: 0.2rem;
            font-size: 0.38rem;
            text-align: center;
            &::after {
              content: "";
              position: absolute;
              bottom: -30%;
              left: 0;
              width: 0.5rem;
              height: 0.05rem;
              background: #333;
            }
          }
          .imgBox {
            position: absolute;
            bottom: 0;
            right: 0;
            display: block;
            margin: auto;
            width: 2.4rem;
            height: 2.4rem;
            img {
              width: 100%;
            }
          }
          &:first-child {
            background: #f9f3e4;
          }
        }
      }
    }
    .shoppingGuideModule {
      display: flex;
      justify-content: space-between;
      background: #fff;
      padding: 0.2rem 0.4rem 0.4rem 0.4rem;
      margin-bottom: .3rem;
      .shoppingGuideBox {
        background: #eeeeee;
        width: 4.17rem;
        padding: 0.2rem;
        .title {
          font-size: 0.4rem;
          padding-left: 0.2rem;
          height: 0.6rem;
          line-height: 0.6rem;
        }
        .desc {
          padding-left: 0.2rem;
        }
        a {
          width: 0.2rem;
          margin: 0 0.05rem;
          .imgBox {
            img {
              width: 2rem;
            }
          }
        }
      }
    }
  }
  .skeleton-box {
    background: #fff;
    width: 100%;
    .skeleton-image {
      position: relative;
      display: block;
      width: 100%;
      top: -1.4rem;
      left: 0;
    }
  }
}
</style>